package gui;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JButton;
import javax.swing.Timer;

import card.Card;

/**
 * 
 * @author Oskar
 * A ordinary JButton with a size to match the card images, as well as a card variable.
 */
public class CardButton extends JButton implements MouseMotionListener,MouseListener, ActionListener {
	Point latestPoint = new Point(0,0);
	Point currentPoint = new Point(0,0);
	Timer mouseovertimer = new Timer(100, (ActionListener) this);
	private Card card;
	private static ImageHandler imageHandler = ImageHandler.getInstance();
	
	public CardButton(Card c){
		card = c;
		//mouseovertimer.start();
		//setText(card.getName());
		this.setPreferredSize(new Dimension(48, 48));
		this.setIcon((imageHandler.getImageIcon(c.getImageSmall())));
		addMouseMotionListener(this);
		addMouseListener(this);
		//this.setIcon(card.getIconSmall());
		/*Border buttonBorder;
		if(c instanceof CreatureCard){
			buttonBorder = new LineBorder(Color.red, 1);
			this.setBorder(buttonBorder);
		}		*/
	}
	
	public Card getCard(){
		return card;
	}

	@Override
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent  e) {
		currentPoint = getPoint(e);
	}

	public Point getPoint(MouseEvent e){
		return new Point(e.getX(),e.getY());
	}
	
	public void actionPerformed(ActionEvent e) {
		/*if(latestPoint.equals(currentPoint)){
					Card cardToShow = getCard();
					CardViewPanel.getInstance().setShownCard(cardToShow);
					CardViewPanel.getInstance().repaint();
	 	}
		latestPoint = currentPoint;*/
	}

	

	@Override
	public void mouseEntered(MouseEvent e) {
		mouseovertimer.start();
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		mouseovertimer.stop();
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}
